package com.fenyin.samples.study.regex;  

import java.util.ArrayList;
import java.util.List;
  
public class LogMonitor {
    
	private String symbolPattern="([\\s@&(),<>\\*\\/\\/$'\\\";\\;\\?!~|\\[\\]:])|([\\-\\._]{2,})";
	
	private static final String URL_PREFIX = ".com/";
	
	public String[] index(String msg) {
		String[] result = new String[0];
		try {
			if (msg == null) {
				return result;
			}
			msg = msg.trim();
			msg = msg.replaceAll(symbolPattern, " ");
			String[] tempresult = msg.split(" ");
			List<String> tempResultList = new ArrayList<String>();
			for (String tempStr : tempresult) {
				if (tempStr != null && tempStr.length() >= 3) {
					tempResultList.add(tempStr);
				}
			}
			if (tempResultList != null && tempResultList.size() > 0) {
				result = tempResultList.toArray(new String[0]);
			}
		} catch (Throwable e) {
			
		}
		return result;
	}
	
	public static String parseDispName(String fullPath){
		int beginIndex= fullPath.indexOf(URL_PREFIX)+URL_PREFIX.length();
		int endIndex=fullPath.indexOf("/",beginIndex);
		return fullPath.substring(beginIndex, endIndex);
	}
	
	public static void main(String[] args){
		LogMonitor logMonitor = new LogMonitor();
//		String[] srcs = logMonitor.index("esb-receiver-rec-sys-error");
		String[] srcs = logMonitor.index("[12-08 00:30:13 135 INFO ] [pool-1-thread-1] infomanage.schedule.InfoMsgCleanSchedule -  schedule-clean$begin#");
		System.out.println(parseDispName("http://fabu.58.com/ershouche/10542946852484x.shtml"));
	}
}
